// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const teamRequest = {
  // dict请求的基本url
  BASE_URL: confing.CAL_URL + "/cal",

  //根据班组编码查班组信息
  selectByTeamCode(teamCode,callback){
    let url = this.BASE_URL + "/selectByTeamCode?teamCode=" + teamCode;
    // 发送请求
    request.get(url,callback);
  },
  //查询全部班组数据
  getList(callback){
    let url = this.BASE_URL + "/getList";
    // 发送请求
    request.get(url,callback);
  },
  // 删除班组,同时删除班组与用户的关系
  deleteById(teamCodes,callback){
    // 拼接URL
    let url = this.BASE_URL + "/deleteById?t=1";
    if(teamCodes != undefined){
      teamCodes.forEach(teamCode => {
            url += "&teamCodes=" + teamCode;
        });
        request.delete( url,callback);
    }
  },
  // 更改班组数据
  update(team,callback){
    let url = this.BASE_URL + "/update";
    request.put(url,team,callback);
  },
  //根据id查询班组数据
  selectByTeamId(teamId,callback){
    let url = this.BASE_URL + "/selectByTeamId?teamId=" + teamId;
    // 发送请求
    request.get(url,callback);
  },
  //添加班组数据
  save(team,callback){
    let url = this.BASE_URL + "/save";
    request.post(url,team,callback);
},
  // 请求的API
  list(page = 1, limit = 10, team, callbcak) {
    // url
    let url = this.BASE_URL + "/list?page=" + page +
      "&limit=" + limit;
    if (team) {
      if (team.teamTypeId) {
        url += "&teamTypeId=" + team.teamTypeId;
      }
      if (team.teamId) {
        url += "&teamId=" + team.teamId;
      }
      if (team.teamName) {
        url += "&teamName=" + team.teamName;
      }
      if (team.teamCode) {
        url += "&teamCode=" + team.teamCode;
      }
    }
    // 发送请求
    request.get(url, callbcak);
  }
}
// 将dictRequest暴漏出去
export default teamRequest;